<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { getPeiSongDianAPI } from '@/services/category'
import type { PeiSongDian } from '@/types/address'
import { useMemberStore } from '@/stores'

// 获取会员Store
const memberStore = useMemberStore()
console.log(memberStore.profile)
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
// 是否数据加载完毕
const isFinish = ref(false)
//活动经纬度信息
const location = ref({
  latitude: 0.00,
  longitude: 0.00
})
const peisongdianlist = ref<PeiSongDian[]>([])
const peisongdian = ref('')
//获取定位
const getMealList = async () => {
  const res = await wx.getLocation({
    type: 'wgs84',
    success(res) {
      location.value.latitude = res.latitude
      location.value.longitude = res.longitude
      getPeiSongDian()
      //const speed = res.speed
      //const accuracy = res.accuracy
    }
  })
}

//获取配送点
const getPeiSongDian = async () => {
  const res = await getPeiSongDianAPI(location.value)
  peisongdianlist.value = res.result
  peisongdian.value = peisongdianlist.value[0].name
}
const selectAddress = () => {
  uni.navigateTo({ url: '/pages/myaddress/myaddress' })
}

//计算配送点
const calDistance = async () => {
  getMealList()
}
// 组件挂载完毕
/*onMounted(() => {
  calDistance()
})*/
</script>

<template>
  <view class="navbar" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
    <!-- logo文字 -->
    <view class="logo">
      <text class="logo-image">湘味小厨</text>
    </view>
    <!--定位-->
    <view class="location">
      <image class="location-image" src="@/static/tabs/location.png"></image>
      <text class="location-text: ">配送点: {{ peisongdian }}</text>
      <button class="location-button" @tap="selectAddress">选择配送点</button>

    </view>
    <!--定位-->
  </view>
</template>

<style lang="scss">
/* 自定义导航条 */
.navbar {
  background-image: url(@/static/images/navigator_bg.png);
  background-size: cover;
  position: relative;
  display: flex;
  flex-direction: column;
  padding-top: 20px;

  .logo {
    display: flex;
    align-items: center;
    height: 64rpx;
    padding-left: 30rpx;

    .logo-image {
      flex: 1;
      color: #fff;
      padding-left: 2rpx;
      font-size: 40rpx;
    }

    .logo-text {
      flex: 1;
      line-height: 28rpx;
      color: #fff;
      margin: 2rpx 0 0 20rpx;
      padding-left: 2rpx;
      border-left: 1rpx solid #fff;
      font-size: 26rpx;
    }
  }

  .location {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 10rpx 0 26rpx;
    height: 64rpx;
    margin: 16rpx 20rpx 0rpx 20rpx;
    color: #474444;
    font-size: 28rpx;
    border-radius: 10rpx 10rpx 0rpx 0rpx;
    background-color: rgba(255, 255, 255, 0.5);

    .location-button {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 80%;
      margin-right: 0rpx;
      font-size: 28rpx;
      border-radius: 50rpx;
      color: #ffffff;
      background-color: #28bb9c;
    }

    .location-image {
      width: 5%;
      height: 75%;
    }

    .location-text {
      margin-left: 10rpx;
    }
  }

}
</style>
